﻿#include "mem.h"
#include "sigar.h"
#include <iostream>
#include <string.h>
using namespace std;


mem::mem()
{

}

int mem::test_mem()
{
    demo_mem_info mem_info;
    getMemInfo(mem_info);
    return 0;
}

void mem::getMemInfo(demo_mem_info &mem_info)
{
    memset(&mem_info, 0, sizeof(demo_mem_info));
    sigar_t *sigar;
    sigar_open(&sigar);

    sigar_mem_t info;
    //获取内存信息
    sigar_mem_get(sigar, &info);

    mem_info.ram = info.ram;
    mem_info.total = info.total;
    mem_info.used = info.used;
    mem_info.free = info.free;
    mem_info.actual_used = info.actual_used;
    mem_info.actual_free = info.actual_free;
    mem_info.used_percent = info.used_percent;
    mem_info.free_percent = info.free_percent;

    sigar_close(sigar);
}
